/**
 * @file		ct_dd_pmc_hdmac.c
 * @brief		PMC HDMAC driver Component test.
 * @note		None
 * @attention	None
 * <B><I>Copyright 2016 Socionext Inc.</I></B>
 */

#include <stdlib.h>
#include <string.h>
#include "driver_common.h"
#include "ct_dd_pmc_hdmac.h"
#include "dd_pmc_hdmac.h"
#include "pmc.h"

/*----------------------------------------------------------------------*/
/* Definition															*/
/*----------------------------------------------------------------------*/
#define D_PMC_HDMAC_AUTO_TEST_SIZE			(0x96000)

#define D_PMC_HDMAC_SDRAM_BASE				(0x9A000000)
#define D_PMC_HDMAC_AUTO_TEST_ADR_SRC		(D_PMC_HDMAC_SDRAM_BASE)
#define D_PMC_HDMAC_AUTO_TEST_ADR_DST		(D_PMC_HDMAC_SDRAM_BASE + D_PMC_HDMAC_AUTO_TEST_SIZE)

/*----------------------------------------------------------------------*/
/* Enumeration															*/
/*----------------------------------------------------------------------*/

/*----------------------------------------------------------------------*/
/* Global Data															*/
/*----------------------------------------------------------------------*/
static T_DD_PMC_HDMAC_CTRL		gHDMAC_Ctrl[8];
static T_DD_PMC_HDMAC_CTRL_TRNS	gHDMAC_Ctrl_Trns[8];
static T_DD_PMC_HDMAC_TRNS_SIZE	gHDMAC_Trns_Size[8];

static VOID ct_pmc_hdmac_callback( UCHAR ch, USHORT* status )
{
	Ddim_Print(("HDMAC Callback - ch:%d, status:0x%04x\n", ch, *status));
}

static INT32 ct_pmc_hdmac_set_is( UCHAR ch, CHAR* is ){
	INT32 ret = D_DDIM_OK;

	// Set IS
	if (strcmp(is, "soft") == 0) {
		gHDMAC_Ctrl_Trns[ch].mode.input_sel = D_DD_PMC_HDMAC_IS_SOFT;
	}
	else if (strcmp(is, "dreq_h") == 0) {
		gHDMAC_Ctrl_Trns[ch].mode.input_sel = D_DD_PMC_HDMAC_IS_DREQ_H;
	}
	else if (strcmp(is, "dreq_l") == 0) {
		gHDMAC_Ctrl_Trns[ch].mode.input_sel = D_DD_PMC_HDMAC_IS_DREQ_L;
	}
	else if (strcmp(is, "idreq_0") == 0) {
		gHDMAC_Ctrl_Trns[ch].mode.input_sel = D_DD_PMC_HDMAC_IS_IDREQ_0;
	}
	else if (strcmp(is, "idreq_1") == 0) {
		gHDMAC_Ctrl_Trns[ch].mode.input_sel = D_DD_PMC_HDMAC_IS_IDREQ_1;
	}
	else if (strcmp(is, "idreq_2") == 0) {
		gHDMAC_Ctrl_Trns[ch].mode.input_sel = D_DD_PMC_HDMAC_IS_IDREQ_2;
	}
	else if (strcmp(is, "idreq_3") == 0) {
		gHDMAC_Ctrl_Trns[ch].mode.input_sel = D_DD_PMC_HDMAC_IS_IDREQ_3;
	}
	else if (strcmp(is, "idreq_4") == 0) {
		gHDMAC_Ctrl_Trns[ch].mode.input_sel = D_DD_PMC_HDMAC_IS_IDREQ_4;
	}
	else if (strcmp(is, "idreq_5") == 0) {
		gHDMAC_Ctrl_Trns[ch].mode.input_sel = D_DD_PMC_HDMAC_IS_IDREQ_5;
	}
	else if (strcmp(is, "idreq_6") == 0) {
		gHDMAC_Ctrl_Trns[ch].mode.input_sel = D_DD_PMC_HDMAC_IS_IDREQ_6;
	}
	else if (strcmp(is, "idreq_7") == 0) {
		gHDMAC_Ctrl_Trns[ch].mode.input_sel = D_DD_PMC_HDMAC_IS_IDREQ_7;
	}
	else if (strcmp(is, "idreq_8") == 0) {
		gHDMAC_Ctrl_Trns[ch].mode.input_sel = D_DD_PMC_HDMAC_IS_IDREQ_8;
	}
	else if (strcmp(is, "idreq_9") == 0) {
		gHDMAC_Ctrl_Trns[ch].mode.input_sel = D_DD_PMC_HDMAC_IS_IDREQ_9;
	}
	else if (strcmp(is, "idreq_10") == 0) {
		gHDMAC_Ctrl_Trns[ch].mode.input_sel = D_DD_PMC_HDMAC_IS_IDREQ_10;
	}
	else if (strcmp(is, "idreq_11") == 0) {
		gHDMAC_Ctrl_Trns[ch].mode.input_sel = D_DD_PMC_HDMAC_IS_IDREQ_11;
	}
	else if (strcmp(is, "idreq_12") == 0) {
		gHDMAC_Ctrl_Trns[ch].mode.input_sel = D_DD_PMC_HDMAC_IS_IDREQ_12;
	}
	else if (strcmp(is, "idreq_13") == 0) {
		gHDMAC_Ctrl_Trns[ch].mode.input_sel = D_DD_PMC_HDMAC_IS_IDREQ_13;
	}
	else if (strcmp(is, "idreq_14") == 0) {
		gHDMAC_Ctrl_Trns[ch].mode.input_sel = D_DD_PMC_HDMAC_IS_IDREQ_14;
	}
	else if (strcmp(is, "idreq_15") == 0) {
		gHDMAC_Ctrl_Trns[ch].mode.input_sel = D_DD_PMC_HDMAC_IS_IDREQ_15;
	}
	else {
		Ddim_Print(("Parameter ERR. Input Select \n"));
		ret = D_DDIM_INPUT_PARAM_ERROR;
	}
	return ret;
}

/**
 * @brief  Command main function for HDMAC test.
 * @param  INT32 argc	:The number of parameters
 *		   CHAR** argv	:The value of parameters
 * @return VOID
 */
VOID Ct_Dd_Pmc_HDMAC_Main(int argc, char** argv)
{
	INT32				ret;
	INT32				size = 0;
	ULONG				src_addr;
	ULONG				dst_addr;
	ULONG				total_size;
	ULONG				trans_width = 0;
	char*				endstr;
	VP_CALLBACK			intHandler;
	USHORT				status = 0;
	UCHAR				ch;
	UCHAR				prot;
	UCHAR				arb_type;

	if (strcmp(argv[1], "ctrl_cmm") == 0) {
		/* ch number */
		ch = atoi(argv[2]);

		gHDMAC_Ctrl[ch].src_addr = strtoul(argv[3], &endstr, 16);
		gHDMAC_Ctrl[ch].dst_addr = strtoul(argv[4], &endstr, 16);

		ret = Dd_PMC_HDMAC_Ctrl_Common(ch, &gHDMAC_Ctrl[ch]);
		if (ret == 0) {
			Ddim_Print(("Dd_PMC_HDMAC_Ctrl_Common - OK\n"));
		}
		else {
			Ddim_Print(("Dd_PMC_HDMAC_Ctrl_Common - Error. ret=0x%x\n", ret));
		}
	}
	else if (strcmp(argv[1], "ctrl_cmm_cfga") == 0) {
		/* ch number */
		ch = atoi(argv[2]);

		gHDMAC_Ctrl[ch].config_a.word = 0;

		// Set IS
		ret = ct_pmc_hdmac_set_is(ch, argv[3]);
		if( ret != D_DDIM_OK ){
			Ddim_Print(("Parameter ERR. P3 \n"));
			return;
		}

		// Set BT
		if (strcmp(argv[4], "normal") == 0) {
			gHDMAC_Ctrl[ch].config_a.bit.bt = D_DD_PMC_HDMAC_BT_NORMAL;
		}
		else if (strcmp(argv[4], "single") == 0) {
			gHDMAC_Ctrl[ch].config_a.bit.bt = D_DD_PMC_HDMAC_BT_SINGLE;
		}
		else if (strcmp(argv[4], "incr") == 0) {
			gHDMAC_Ctrl[ch].config_a.bit.bt = D_DD_PMC_HDMAC_BT_INCR;
		}
		else if (strcmp(argv[4], "wrap4") == 0) {
			gHDMAC_Ctrl[ch].config_a.bit.bt = D_DD_PMC_HDMAC_BT_WRAP4;
		}
		else if (strcmp(argv[4], "incr4") == 0) {
			gHDMAC_Ctrl[ch].config_a.bit.bt = D_DD_PMC_HDMAC_BT_INCR4;
		}
		else if (strcmp(argv[4], "wrap8") == 0) {
			gHDMAC_Ctrl[ch].config_a.bit.bt = D_DD_PMC_HDMAC_BT_WRAP8;
		}
		else if (strcmp(argv[4], "incr8") == 0) {
			gHDMAC_Ctrl[ch].config_a.bit.bt = D_DD_PMC_HDMAC_BT_INCR8;
		}
		else if (strcmp(argv[4], "wrap16") == 0) {
			gHDMAC_Ctrl[ch].config_a.bit.bt = D_DD_PMC_HDMAC_BT_WRAP16;
		}
		else if (strcmp(argv[4], "incr16") == 0) {
			gHDMAC_Ctrl[ch].config_a.bit.bt = D_DD_PMC_HDMAC_BT_INCR16;
		}
		else {
			Ddim_Print(("Parameter ERR. P4 \n"));
			return;
		}

		// Set BC
		gHDMAC_Ctrl[ch].config_a.bit.bc = atoi(argv[5]);

		// Set TC
		gHDMAC_Ctrl[ch].config_a.bit.tc = atoi(argv[6]);
	}
	else if (strcmp(argv[1], "ctrl_cmm_cfgb") == 0) {
		/* ch number */
		ch = atoi(argv[2]);

		gHDMAC_Ctrl[ch].config_b.word = 0;

		// Set MS
		if (strcmp(argv[3], "blk") == 0) {
			gHDMAC_Ctrl[ch].config_b.bit.ms = D_DD_PMC_HDMAC_MS_BLK;
		}
		else if (strcmp(argv[3], "burst") == 0) {
			gHDMAC_Ctrl[ch].config_b.bit.ms = D_DD_PMC_HDMAC_MS_BURST;
		}
		else if (strcmp(argv[3], "demand") == 0) {
			gHDMAC_Ctrl[ch].config_b.bit.ms = D_DD_PMC_HDMAC_MS_DEMAND;
		}
		else {
			Ddim_Print(("Parameter ERR. P3 \n"));
			return;
		}

		// Set TW
		if (strcmp(argv[4], "1") == 0) {
			gHDMAC_Ctrl[ch].config_b.bit.tw = D_DD_PMC_HDMAC_TW_BYTE;
		}
		else if (strcmp(argv[4], "2") == 0) {
			gHDMAC_Ctrl[ch].config_b.bit.tw = D_DD_PMC_HDMAC_TW_HWORD;
		}
		else if (strcmp(argv[4], "4") == 0) {
			gHDMAC_Ctrl[ch].config_b.bit.tw = D_DD_PMC_HDMAC_TW_WORD;
		}
		else {
			Ddim_Print(("Parameter ERR. P4 \n"));
			return;
		}

		// Set FS
		if (strcmp(argv[5], "src_fix") == 0) {
			gHDMAC_Ctrl[ch].config_b.bit.fs = D_DD_PMC_HDMAC_FS_FIX;
		}
		else if (strcmp(argv[5], "src_incr") == 0) {
			gHDMAC_Ctrl[ch].config_b.bit.fs = D_DD_PMC_HDMAC_FS_INCR;
		}
		else {
			Ddim_Print(("Parameter ERR. P5 \n"));
			return;
		}

		// Set FD
		if (strcmp(argv[6], "dst_fix") == 0) {
			gHDMAC_Ctrl[ch].config_b.bit.fs = D_DD_PMC_HDMAC_FD_FIX;
		}
		else if (strcmp(argv[6], "dst_incr") == 0) {
			gHDMAC_Ctrl[ch].config_b.bit.fs = D_DD_PMC_HDMAC_FD_INCR;
		}
		else {
			Ddim_Print(("Parameter ERR. P6 \n"));
			return;
		}

		// Set RC
		if (strcmp(argv[7], "ena") == 0) {
			gHDMAC_Ctrl[ch].config_b.bit.rc = D_DD_PMC_HDMAC_RC_ENABLE;
		}
		else if (strcmp(argv[7], "dis") == 0) {
			gHDMAC_Ctrl[ch].config_b.bit.rc = D_DD_PMC_HDMAC_RC_DISABLE;
		}
		else {
			Ddim_Print(("Parameter ERR. P7 \n"));
			return;
		}

		// Set RS
		if (strcmp(argv[8], "ena") == 0) {
			gHDMAC_Ctrl[ch].config_b.bit.rs = D_DD_PMC_HDMAC_RS_ENABLE;
		}
		else if (strcmp(argv[8], "dis") == 0) {
			gHDMAC_Ctrl[ch].config_b.bit.rs = D_DD_PMC_HDMAC_RS_DISABLE;
		}
		else {
			Ddim_Print(("Parameter ERR. P8 \n"));
			return;
		}

		// Set RD
		if (strcmp(argv[9], "ena") == 0) {
			gHDMAC_Ctrl[ch].config_b.bit.rd = D_DD_PMC_HDMAC_RD_ENABLE;
		}
		else if (strcmp(argv[9], "dis") == 0) {
			gHDMAC_Ctrl[ch].config_b.bit.rd = D_DD_PMC_HDMAC_RD_DISABLE;
		}
		else {
			Ddim_Print(("Parameter ERR. P9 \n"));
			return;
		}

		// Set SP
		gHDMAC_Ctrl[ch].config_b.bit.sp = atoi(argv[10]);

		// Set DP
		gHDMAC_Ctrl[ch].config_b.bit.dp = atoi(argv[11]);
	}
	else if (strcmp(argv[1], "ctrl_trns_md") == 0) {
		/* ch number */
		ch = atoi(argv[2]);

		// Set IS
		ret = ct_pmc_hdmac_set_is(ch, argv[3]);
		if( ret != D_DDIM_OK ){
			Ddim_Print(("Parameter ERR. P3 \n"));
			return;
		}

		// Set MS
		if (strcmp(argv[4], "blk") == 0) {
			gHDMAC_Ctrl_Trns[ch].mode.mode_sel = D_DD_PMC_HDMAC_MS_BLK;
		}
		else if (strcmp(argv[4], "burst") == 0) {
			gHDMAC_Ctrl_Trns[ch].mode.mode_sel = D_DD_PMC_HDMAC_MS_BURST;
		}
		else if (strcmp(argv[4], "demand") == 0) {
			gHDMAC_Ctrl_Trns[ch].mode.mode_sel = D_DD_PMC_HDMAC_MS_DEMAND;
		}
		else {
			Ddim_Print(("Parameter ERR. P4 \n"));
			return;
		}

		// Set FS
		if (strcmp(argv[5], "src_fix") == 0) {
			gHDMAC_Ctrl_Trns[ch].mode.src_fix = D_DD_PMC_HDMAC_FS_FIX;
		}
		else if (strcmp(argv[5], "src_incr") == 0) {
			gHDMAC_Ctrl_Trns[ch].mode.src_fix = D_DD_PMC_HDMAC_FS_INCR;
		}
		else {
			Ddim_Print(("Parameter ERR. P5 \n"));
			return;
		}

		// Set FD
		if (strcmp(argv[6], "dst_fix") == 0) {
			gHDMAC_Ctrl_Trns[ch].mode.dst_fix = D_DD_PMC_HDMAC_FD_FIX;
		}
		else if (strcmp(argv[6], "dst_incr") == 0) {
			gHDMAC_Ctrl_Trns[ch].mode.dst_fix = D_DD_PMC_HDMAC_FD_INCR;
		}
		else {
			Ddim_Print(("Parameter ERR. P6 \n"));
			return;
		}

		// Set BT
		if (strcmp(argv[7], "normal") == 0) {
			gHDMAC_Ctrl_Trns[ch].mode.beat_type = D_DD_PMC_HDMAC_BT_NORMAL;
		}
		else if (strcmp(argv[7], "single") == 0) {
			gHDMAC_Ctrl_Trns[ch].mode.beat_type = D_DD_PMC_HDMAC_BT_SINGLE;
		}
		else if (strcmp(argv[7], "incr") == 0) {
			gHDMAC_Ctrl_Trns[ch].mode.beat_type = D_DD_PMC_HDMAC_BT_INCR;
		}
		else if (strcmp(argv[7], "wrap4") == 0) {
			gHDMAC_Ctrl_Trns[ch].mode.beat_type = D_DD_PMC_HDMAC_BT_WRAP4;
		}
		else if (strcmp(argv[7], "incr4") == 0) {
			gHDMAC_Ctrl_Trns[ch].mode.beat_type = D_DD_PMC_HDMAC_BT_INCR4;
		}
		else if (strcmp(argv[7], "wrap8") == 0) {
			gHDMAC_Ctrl_Trns[ch].mode.beat_type = D_DD_PMC_HDMAC_BT_WRAP8;
		}
		else if (strcmp(argv[7], "incr8") == 0) {
			gHDMAC_Ctrl_Trns[ch].mode.beat_type = D_DD_PMC_HDMAC_BT_INCR8;
		}
		else if (strcmp(argv[7], "wrap16") == 0) {
			gHDMAC_Ctrl_Trns[ch].mode.beat_type = D_DD_PMC_HDMAC_BT_WRAP16;
		}
		else if (strcmp(argv[7], "incr16") == 0) {
			gHDMAC_Ctrl_Trns[ch].mode.beat_type = D_DD_PMC_HDMAC_BT_INCR16;
		}
		else {
			Ddim_Print(("Parameter ERR. P7 \n"));
			return;
		}
	}
	else if (strcmp(argv[1], "ctrl_trns_sz") == 0) {
		/* ch number */
		ch = atoi(argv[2]);

		// Set TW
		if (strcmp(argv[3], "1") == 0) {
			gHDMAC_Ctrl_Trns[ch].size.trns_width = D_DD_PMC_HDMAC_TW_BYTE;
		}
		else if (strcmp(argv[3], "2") == 0) {
			gHDMAC_Ctrl_Trns[ch].size.trns_width = D_DD_PMC_HDMAC_TW_HWORD;
		}
		else if (strcmp(argv[3], "4") == 0) {
			gHDMAC_Ctrl_Trns[ch].size.trns_width = D_DD_PMC_HDMAC_TW_WORD;
		}
		else {
			Ddim_Print(("Parameter ERR. P3 \n"));
			return;
		}

		// Set Size
		gHDMAC_Ctrl_Trns[ch].size.trns_size = atoi(argv[4]);

		gHDMAC_Ctrl_Trns[ch].size.src_addr = strtoul(argv[5], &endstr, 16);

		gHDMAC_Ctrl_Trns[ch].size.dst_addr = strtoul(argv[6], &endstr, 16);
		
		ret = Dd_PMC_HDMAC_Ctrl_Trns(ch, &gHDMAC_Ctrl_Trns[ch]);
		if (ret == 0) {
			Ddim_Print(("Dd_PMC_HDMAC_Ctrl_Trns - OK\n"));
		}
		else {
			Ddim_Print(("Dd_PMC_HDMAC_Ctrl_Trns - Error. ret=0x%x\n", ret));
		}
	}
	else if (strcmp(argv[1], "start") == 0) {
		/* ch number */
		ch = atoi(argv[2]);

		ret = Dd_PMC_HDMAC_Start_Async(ch, (VP_CALLBACK)ct_pmc_hdmac_callback);
		if (ret == 0) {
			Ddim_Print(("Dd_PMC_HDMAC_Start_Async - OK\n"));
		}
		else {
			Ddim_Print(("Dd_PMC_HDMAC_Start_Async - Error. ret=0x%x\n", ret));
		}
	}
	else if (strcmp(argv[1], "stop") == 0) {
		/* ch number */
		ch = atoi(argv[2]);

		ret = Dd_PMC_HDMAC_Stop(ch);
		if (ret == 0) {
			Ddim_Print(("Dd_PMC_HDMAC_Stop - OK\n"));
		}
		else {
			Ddim_Print(("Dd_PMC_HDMAC_Stop - Error. ret=0x%x\n", ret));
		}
	}
	else if (strcmp(argv[1], "pause") == 0) {
		/* ch number */
		ch = atoi(argv[2]);

		ret = Dd_PMC_HDMAC_Pause(ch);
		if (ret == 0) {
			Ddim_Print(("Dd_PMC_HDMAC_Pause - OK\n"));
		}
		else {
			Ddim_Print(("Dd_PMC_HDMAC_Pause - Error. ret=0x%x\n", ret));
		}
	}
	else if (strcmp(argv[1], "resume") == 0) {
		/* ch number */
		ch = atoi(argv[2]);

		ret = Dd_PMC_HDMAC_Resume(ch);
		if (ret == 0) {
			Ddim_Print(("Dd_PMC_HDMAC_Resume - OK\n"));
		}
		else {
			Ddim_Print(("Dd_PMC_HDMAC_Resume - Error. ret=0x%x\n", ret));
		}
	}
	else if (strcmp(argv[1], "status_clear") == 0) {
		/* ch number */
		ch = atoi(argv[2]);

		ret = Dd_PMC_HDMAC_Clear_Status(ch);
		if (ret == 0) {
			Ddim_Print(("Dd_PMC_HDMAC_Clear_Status - OK\n"));
		}
		else {
			Ddim_Print(("Dd_PMC_HDMAC_Clear_Status - Error. ret=0x%x\n", ret));
		}
	}
	else if (strcmp(argv[1], "status_read") == 0) {
		/* ch number */
		ch = atoi(argv[2]);

		ret = Dd_PMC_HDMAC_Get_Status(ch, &status);
		if (ret == 0) {
			Ddim_Print(("Dd_PMC_HDMAC_Get_Status - OK. status=0x%x\n", status));
		}
		else {
			Ddim_Print(("Dd_PMC_HDMAC_Get_Status - Error. ret=0x%x\n", ret));
		}
	}
	else if (strcmp(argv[1], "trns_size_set") == 0) {
		/* ch number */
		ch = atoi(argv[2]);

		// Set TW
		if (strcmp(argv[3], "1") == 0) {
			gHDMAC_Trns_Size[ch].trns_width = D_DD_PMC_HDMAC_TW_BYTE;
		}
		else if (strcmp(argv[3], "2") == 0) {
			gHDMAC_Trns_Size[ch].trns_width = D_DD_PMC_HDMAC_TW_HWORD;
		}
		else if (strcmp(argv[3], "4") == 0) {
			gHDMAC_Trns_Size[ch].trns_width = D_DD_PMC_HDMAC_TW_WORD;
		}
		else {
			Ddim_Print(("Parameter ERR. P3 \n"));
			return;
		}
		gHDMAC_Trns_Size[ch].trns_size = atoi(argv[4]);
		gHDMAC_Trns_Size[ch].src_addr = strtoul(argv[5], &endstr, 16);
		gHDMAC_Trns_Size[ch].dst_addr = strtoul(argv[6], &endstr, 16);

		ret = Dd_PMC_HDMAC_Set_Trns_Size(ch, &gHDMAC_Trns_Size[ch]);
		if ( ret == D_DDIM_OK ) {
			Ddim_Print(("Dd_PMC_HDMAC_Set_Trns_Size - OK\n"));
		}
		else {
			Ddim_Print(("Dd_PMC_HDMAC_Set_Trns_Size - Error. ret=0x%x\n", ret));
		}
	}
	else if (strcmp(argv[1], "trns_size_get") == 0) {
		/* ch number */
		ch = atoi(argv[2]);

		size = Dd_PMC_HDMAC_Get_Trns_Size(ch);
		Ddim_Print(("Dd_PMC_HDMAC_Get_Trns_Size - Size=%d\n", size));
	}
	else if (strcmp(argv[1], "rmn_size_get") == 0) {
		/* ch number */
		ch = atoi(argv[2]);

		size = Dd_PMC_HDMAC_Get_Remain_Trns_Size(ch);
		Ddim_Print(("Dd_PMC_HDMAC_Get_Remain_Trns_Size - Size=%d\n", size));
	}
	else if (strcmp(argv[1], "total_size_get") == 0) {
		/* ch number */
		ch = atoi(argv[2]);

		size = Dd_PMC_HDMAC_Get_Total_Trns_Size(ch);
		Ddim_Print(("Dd_PMC_HDMAC_Get_Total_Trns_Size - Size=%d\n", size));
	}
	else if (strcmp(argv[1], "src_addr_get") == 0) {
		/* ch number */
		ch = atoi(argv[2]);

		src_addr = Dd_PMC_HDMAC_Get_Src_Addr(ch);
		Ddim_Print(("Dd_PMC_HDMAC_Get_Src_Addr - Src Addr=0x%08x\n", src_addr));
	}
	else if (strcmp(argv[1], "dst_addr_get") == 0) {
		/* ch number */
		ch = atoi(argv[2]);

		dst_addr = Dd_PMC_HDMAC_Get_Dst_Addr(ch);
		Ddim_Print(("Dd_PMC_HDMAC_Get_Dst_Addr - Dst Addr=0x%08x\n", dst_addr));
	}
	else if (strcmp(argv[1], "src_addr_set") == 0) {
		/* ch number */
		ch = atoi(argv[2]);
		src_addr = strtoul(argv[3], &endstr, 16);

		ret = Dd_PMC_HDMAC_Set_Src_Addr(ch, src_addr);			/* pgr0539 */
		if (ret == 0) {
			Ddim_Print(("Dd_PMC_HDMAC_Set_Src_Addr - OK\n"));
		}
		else {
			Ddim_Print(("Dd_PMC_HDMAC_Set_Src_Addr - Error. ret=0x%x\n", ret));
		}
	}
	else if (strcmp(argv[1], "dst_addr_set") == 0) {
		/* ch number */
		ch = atoi(argv[2]);
		dst_addr = strtoul(argv[3], &endstr, 16);

		ret = Dd_PMC_HDMAC_Set_Dst_Addr(ch, dst_addr);			/* pgr0539 */
		if (ret == 0) {
			Ddim_Print(("Dd_PMC_HDMAC_Set_Dst_Addr - OK\n"));
		}
		else {
			Ddim_Print(("Dd_PMC_HDMAC_Set_Dst_Addr - Error. ret=0x%x\n", ret));
		}
	}
	else if (strcmp(argv[1], "src_prot_set") == 0) {
		/* ch number */
		ch = atoi(argv[2]);
		prot = atoi(argv[3]);

		ret = Dd_PMC_HDMAC_Set_Source_Protect(ch, prot);
		if (ret == 0) {
			Ddim_Print(("Dd_PMC_HDMAC_Set_Source_Protect - OK\n"));
		}
		else {
			Ddim_Print(("Dd_PMC_HDMAC_Set_Source_Protect - Error. ret=0x%x\n", ret));
		}
	}
	else if (strcmp(argv[1], "dst_prot_set") == 0) {
		/* ch number */
		ch = atoi(argv[2]);
		prot = atoi(argv[3]);

		ret = Dd_PMC_HDMAC_Set_Destination_Protect(ch, prot);
		if (ret == 0) {
			Ddim_Print(("Dd_PMC_HDMAC_Set_Destination_Protect - OK\n"));
		}
		else {
			Ddim_Print(("Dd_PMC_HDMAC_Set_Destination_Protect - Error. ret=0x%x\n", ret));
		}
	}
	else if (strcmp(argv[1], "arb_set") == 0) {
		if (strcmp(argv[2], "rotate") == 0) {
			arb_type = D_DD_PMC_HDMAC_ARB_ROTATE;
		}
		else if (strcmp(argv[2], "fix") == 0) {
			arb_type = D_DD_PMC_HDMAC_ARB_FIX;
		}
		else {
			Ddim_Print(("Parameter ERR P2. \n"));
			return;
		}

		ret = Dd_PMC_HDMAC_Set_Arbitration(arb_type);
		if (ret == 0) {
			Ddim_Print(("Dd_PMC_HDMAC_Set_Arbitration - OK\n"));
		}
		else {
			Ddim_Print(("Dd_PMC_HDMAC_Set_Arbitration - Error. ret=0x%x\n", ret));
		}
	}
	else if (strcmp(argv[1], "arb_get") == 0) {
		
		ret = Dd_PMC_HDMAC_Get_Arbitration(&arb_type);
		if (ret == 0) {
			Ddim_Print(("Dd_PMC_HDMAC_Get_Arbitration - arb_type=0x%x\n", arb_type));
		}
		else {
			Ddim_Print(("Dd_PMC_HDMAC_Get_Arbitration - Error. ret=0x%x\n", ret));
		}
	}
	else if (strcmp(argv[1], "arb_clear") == 0) {
		Dd_PMC_HDMAC_Clear_Arbitration();
		Ddim_Print(("Dd_PMC_HDMAC_Clear_Arbitration\n"));
	}
	else if (strcmp(argv[1], "stop_all") == 0) {
		Dd_PMC_HDMAC_Stop_All_Ch();
		Ddim_Print(("Dd_PMC_HDMAC_Stop_All_Ch\n"));
	}
	else if (strcmp(argv[1], "resume_all") == 0) {
		Dd_PMC_HDMAC_Resume_All_Ch();
		Ddim_Print(("Dd_PMC_HDMAC_Resume_All_Ch\n"));
	}
	else if (strcmp(argv[1], "get_width") == 0) {
		src_addr = strtoul(argv[2], &endstr, 16);
		dst_addr = strtoul(argv[3], &endstr, 16);
		total_size = atoi(argv[4]);

		trans_width = Dd_PMC_HDMAC_Get_Trns_Width(src_addr, dst_addr, total_size);	/* pgr0539 */
		Ddim_Print(("Dd_PMC_HDMAC_Get_Trns_Width - trans_width=%d\n", trans_width));
	}
	else if (strcmp(argv[1], "int_set") == 0) {
		/* ch number */
		ch = atoi(argv[2]);

		intHandler = (VP_CALLBACK)ct_pmc_hdmac_callback;

		Dd_PMC_HDMAC_Set_Int_Handler(ch, intHandler);
		Ddim_Print(("Dd_PMC_HDMAC_Set_Int_Handler\n"));
	}
	else if (strcmp(argv[1], "int_handler") == 0) {
		/* ch number */
		ch = atoi(argv[2]);

		Dd_PMC_HDMAC_Int_Handler(ch);
	}
	else if (strcmp(argv[1], "sdram_async") == 0) {
		/* ch number */
		ch = atoi(argv[2]);

		src_addr = strtoul(argv[3], &endstr, 16);
		dst_addr = strtoul(argv[4], &endstr, 16);
		size = atoi(argv[5]);
		intHandler = (VP_CALLBACK)ct_pmc_hdmac_callback;

		ret = Dd_PMC_HDMAC_Copy_SDRAM_Async(ch, src_addr, dst_addr, size, intHandler);	/* pgr0539 */
		if (ret == 0) {
			Ddim_Print(("Dd_PMC_HDMAC_Copy_SDRAM_Async - OK\n"));
		}
		else {
			Ddim_Print(("Dd_PMC_HDMAC_Copy_SDRAM_Async - Error. ret=0x%x\n", ret));
		}
	}
	else if(strcmp(argv[1], "cmp") == 0) {
		Ddim_Print(("cmp = %d\n", memcmp((void*)strtoul(argv[2], &endstr, 16), (void*)strtoul(argv[3], &endstr, 16), atoi(argv[4]))));
	}
	else if (strcmp(argv[1], "err") == 0){
		T_DD_PMC_HDMAC_CTRL      hdmac_ctrl;
		T_DD_PMC_HDMAC_CTRL_TRNS hdmac_ctrl_trns;
		T_DD_PMC_HDMAC_TRNS_SIZE hdmac_trns_size;
		USHORT status;
		int num;

		hdmac_ctrl_trns.mode.input_sel  = D_DD_PMC_HDMAC_IS_SOFT;
		hdmac_ctrl_trns.mode.mode_sel   = D_DD_PMC_HDMAC_MS_BLK;
		hdmac_ctrl_trns.mode.src_fix    = D_DD_PMC_HDMAC_FS_INCR;
		hdmac_ctrl_trns.mode.dst_fix    = D_DD_PMC_HDMAC_FD_INCR;
		hdmac_ctrl_trns.mode.beat_type  = D_DD_PMC_HDMAC_BT_NORMAL;
		hdmac_ctrl_trns.size.trns_width = D_DD_PMC_HDMAC_TW_WORD;
		hdmac_ctrl_trns.size.trns_size  = D_PMC_HDMAC_AUTO_TEST_SIZE;
		hdmac_ctrl_trns.size.src_addr   = D_PMC_HDMAC_AUTO_TEST_ADR_SRC;
		hdmac_ctrl_trns.size.dst_addr   = D_PMC_HDMAC_AUTO_TEST_ADR_DST;

		hdmac_trns_size.trns_width      = D_DD_PMC_HDMAC_TW_WORD;
		hdmac_trns_size.trns_size       = D_PMC_HDMAC_AUTO_TEST_SIZE;
		hdmac_trns_size.src_addr        = D_PMC_HDMAC_AUTO_TEST_ADR_SRC;
		hdmac_trns_size.dst_addr        = D_PMC_HDMAC_AUTO_TEST_ADR_DST;

		num = atoi(argv[2]);
		switch( num ) {
		case 1:
			ret = Dd_PMC_HDMAC_Ctrl_Common(D_DD_PMC_HDMAC_CH_NUM_MAX, &hdmac_ctrl);
			Ddim_Print(("Dd_PMC_HDMAC_Ctrl_Common(): Channel number is illegal. ret=0x%x\n", ret));
			break;
		case 2:
			ret = Dd_PMC_HDMAC_Ctrl_Common(0, NULL);
			Ddim_Print(("Dd_PMC_HDMAC_Ctrl_Common(): ctrl is NULL. ret=0x%x\n", ret));
			break;
		case 3:
			ret = Dd_PMC_HDMAC_Ctrl_Trns(D_DD_PMC_HDMAC_CH_NUM_MAX, &hdmac_ctrl_trns);
			Ddim_Print(("Dd_PMC_HDMAC_Ctrl_Trns(): Channel number is illegal. ret=0x%x\n", ret));
			break;
		case 4:
			ret = Dd_PMC_HDMAC_Ctrl_Trns(0, NULL);
			Ddim_Print(("Dd_PMC_HDMAC_Ctrl_Trns(): ctrl is NULL. ret=0x%x\n", ret));
			break;
		case 5:
			// BC over test (Ctrl_Trns)
			hdmac_ctrl_trns.size.trns_size  = 0x00440000;	// 65536*4*17
			ret = Dd_PMC_HDMAC_Ctrl_Trns(0, &hdmac_ctrl_trns);
			Ddim_Print(("Dd_PMC_HDMAC_Ctrl_Trns(): BC is over. ret=0x%x\n", ret));
			break;
		case 6:
			// BC over test in Demand mode (Ctrl_Trns)
			hdmac_ctrl_trns.mode.mode_sel  = D_DD_PMC_HDMAC_MS_DEMAND;
			hdmac_ctrl_trns.size.trns_size = 0x00080000;	// 65536*4*2
			ret = Dd_PMC_HDMAC_Ctrl_Trns(0, &hdmac_ctrl_trns);
			Ddim_Print(("Dd_PMC_HDMAC_Ctrl_Trns(): demand transfer and BC is not 0. ret=0x%x\n", ret));
			break;
		case 7:
			// Illegal Alignment (Ctrl_Trns)
			hdmac_ctrl_trns.size.trns_size  = D_PMC_HDMAC_AUTO_TEST_SIZE + 1;
			ret = Dd_PMC_HDMAC_Ctrl_Trns(0, &hdmac_ctrl_trns);
			Ddim_Print(("Dd_PMC_HDMAC_Ctrl_Trns(): illegal alignment. ret=0x%x\n", ret));
			break;
		case 8:
			ret = Dd_PMC_HDMAC_Set_Trns_Size(D_DD_PMC_HDMAC_CH_NUM_MAX, &hdmac_trns_size);
			Ddim_Print(("Dd_PMC_HDMAC_Set_Trns_Size(): Channel number is illegal. ret=0x%x\n", ret));
			break;
		case 9:
			ret = Dd_PMC_HDMAC_Set_Trns_Size(0, NULL);
			Ddim_Print(("Dd_PMC_HDMAC_Set_Trns_Size(): trns_size is NULL. ret=0x%x\n", ret));
			break;
		case 10:
			// BC over test (Set_Trns_Size)
			hdmac_ctrl_trns.mode.mode_sel  = D_DD_PMC_HDMAC_MS_BLK;
			hdmac_ctrl_trns.size.trns_size = 0x00001000;
			ret = Dd_PMC_HDMAC_Ctrl_Trns(0, &hdmac_ctrl_trns);
			hdmac_trns_size.trns_size      = 0x00110000;	// 65536*1*17
			ret = Dd_PMC_HDMAC_Set_Trns_Size(0, &hdmac_trns_size);
			Ddim_Print(("Dd_PMC_HDMAC_Set_Trns_Size(): BC is over. ret=0x%x\n", ret));
			break;
		case 11:
			// BC over test in Demand mode (Set_Trns_Size)
			hdmac_ctrl_trns.mode.mode_sel  = D_DD_PMC_HDMAC_MS_DEMAND;
			hdmac_ctrl_trns.size.trns_size = 0x00001000;
			ret = Dd_PMC_HDMAC_Ctrl_Trns(0, &hdmac_ctrl_trns);
			hdmac_trns_size.trns_size      = 0x00020000;	// 65536*1*2
			ret = Dd_PMC_HDMAC_Set_Trns_Size(0, &hdmac_trns_size);
			Ddim_Print(("Dd_PMC_HDMAC_Set_Trns_Size(): demand transfer and BC is not 0. ret=0x%x\n", ret));
			break;
		case 12:
			// Illegal Alignment (Set_Trns_Size)
			hdmac_trns_size.trns_size      = D_PMC_HDMAC_AUTO_TEST_SIZE + 1;
			ret = Dd_PMC_HDMAC_Set_Trns_Size(0, &hdmac_trns_size);
			Ddim_Print(("Dd_PMC_HDMAC_Set_Trns_Size(): illegal alignment. ret=0x%x\n", ret));
			break;
		case 13:
			ret = Dd_PMC_HDMAC_Start_Async(D_DD_PMC_HDMAC_CH_NUM_MAX, (VP_CALLBACK)ct_pmc_hdmac_callback);
			Ddim_Print(("Dd_PMC_HDMAC_Start_Async(): Channel number is illegal. ret=0x%x\n", ret));
			break;
		case 14:
			ret = Dd_PMC_HDMAC_Stop(D_DD_PMC_HDMAC_CH_NUM_MAX);
			Ddim_Print(("Dd_PMC_HDMAC_Stop(): Channel number is illegal. ret=0x%x\n", ret));
			break;
		case 15:
			ret = Dd_PMC_HDMAC_Pause(D_DD_PMC_HDMAC_CH_NUM_MAX);
			Ddim_Print(("Dd_PMC_HDMAC_Pause(): Channel number is illegal. ret=0x%x\n", ret));
			break;
		case 16:
			ret = Dd_PMC_HDMAC_Resume(D_DD_PMC_HDMAC_CH_NUM_MAX);
			Ddim_Print(("Dd_PMC_HDMAC_Resume(): Channel number is illegal. ret=0x%x\n", ret));
			break;
		case 17:
			ret = Dd_PMC_HDMAC_Clear_Status(D_DD_PMC_HDMAC_CH_NUM_MAX);
			Ddim_Print(("Dd_PMC_HDMAC_Clear_Status(): Channel number is illegal. ret=0x%x\n", ret));
			break;
		case 18:
			ret = Dd_PMC_HDMAC_Get_Status(D_DD_PMC_HDMAC_CH_NUM_MAX, &status);
			Ddim_Print(("Dd_PMC_HDMAC_Get_Status(): Channel number is illegal. ret=0x%x\n", ret));
			break;
		case 19:
			ret = Dd_PMC_HDMAC_Get_Status(0, NULL);
			Ddim_Print(("Dd_PMC_HDMAC_Get_Status(): status is NULL. ret=0x%x\n", ret));
			break;
		case 20:
			ret = Dd_PMC_HDMAC_Get_Trns_Size(D_DD_PMC_HDMAC_CH_NUM_MAX);
			Ddim_Print(("Dd_PMC_HDMAC_Get_Trns_Size(): Channel number is illegal. ret=0x%x\n", ret));
			break;
		case 21:
			ret = Dd_PMC_HDMAC_Get_Remain_Trns_Size(D_DD_PMC_HDMAC_CH_NUM_MAX);
			Ddim_Print(("Dd_PMC_HDMAC_Get_Remain_Trns_Size(): Channel number is illegal. ret=0x%x\n", ret));
			break;
		case 22:
			ret = Dd_PMC_HDMAC_Get_Total_Trns_Size(D_DD_PMC_HDMAC_CH_NUM_MAX);
			Ddim_Print(("Dd_PMC_HDMAC_Get_Total_Trns_Size(): Channel number is illegal. ret=0x%x\n", ret));
			break;
		case 23:
			ret = Dd_PMC_HDMAC_Get_Src_Addr(D_DD_PMC_HDMAC_CH_NUM_MAX);
			Ddim_Print(("Dd_PMC_HDMAC_Get_Src_Addr(): Channel number is illegal. ret=0x%x\n", ret));
			break;
		case 24:
			ret = Dd_PMC_HDMAC_Get_Dst_Addr(D_DD_PMC_HDMAC_CH_NUM_MAX);
			Ddim_Print(("Dd_PMC_HDMAC_Get_Dst_Addr(): Channel number is illegal. ret=0x%x\n", ret));
			break;
		case 25:
			ret = Dd_PMC_HDMAC_Set_Src_Addr(D_DD_PMC_HDMAC_CH_NUM_MAX, D_PMC_HDMAC_AUTO_TEST_ADR_SRC);
			Ddim_Print(("Dd_PMC_HDMAC_Set_Src_Addr(): Channel number is illegal. ret=0x%x\n", ret));
			break;
		case 26:
			ret = Dd_PMC_HDMAC_Set_Dst_Addr(D_DD_PMC_HDMAC_CH_NUM_MAX, D_PMC_HDMAC_AUTO_TEST_ADR_DST);
			Ddim_Print(("Dd_PMC_HDMAC_Set_Dst_Addr(): Channel number is illegal. ret=0x%x\n", ret));
			break;
		case 27:
			ret = Dd_PMC_HDMAC_Set_Source_Protect(D_DD_PMC_HDMAC_CH_NUM_MAX, 0);
			Ddim_Print(("Dd_PMC_HDMAC_Set_Source_Protect(): Channel number is illegal. ret=0x%x\n", ret));
			break;
		case 28:
			ret = Dd_PMC_HDMAC_Set_Destination_Protect(D_DD_PMC_HDMAC_CH_NUM_MAX, 0);
			Ddim_Print(("Dd_PMC_HDMAC_Set_Destination_Protect(): Channel number is illegal. ret=0x%x\n", ret));
			break;
		case 29:
			ret = Dd_PMC_HDMAC_Set_Arbitration(D_DD_PMC_HDMAC_ARB_ROTATE+1);
			Ddim_Print(("Dd_PMC_HDMAC_Set_Arbitration(): arbitration is illegal. ret=0x%x\n", ret));
			break;
		case 30:
			ret = Dd_PMC_HDMAC_Get_Arbitration(NULL);
			Ddim_Print(("Dd_PMC_HDMAC_Get_Arbitration(): arbitration is NULL. ret=0x%x\n", ret));
			break;
		case 31:
			ret = Dd_PMC_HDMAC_Copy_SDRAM_Async(D_DD_PMC_HDMAC_CH_NUM_MAX, 1, 2, 1, (VP_CALLBACK)ct_pmc_hdmac_callback);
			Ddim_Print(("Dd_PMC_HDMAC_Copy_SDRAM_Async(): Channel number is illegal. ret=0x%x\n", ret));
			break;
		case 32:
			ret = Dd_PMC_HDMAC_Copy_SDRAM_Async(0, 0, 2, 1, (VP_CALLBACK)ct_pmc_hdmac_callback);
			Ddim_Print(("Dd_PMC_HDMAC_Copy_SDRAM_Async(): src_addr is illegal. ret=0x%x\n", ret));
			break;
		case 33:
			ret = Dd_PMC_HDMAC_Copy_SDRAM_Async(0, 1, 0, 1, (VP_CALLBACK)ct_pmc_hdmac_callback);
			Ddim_Print(("Dd_PMC_HDMAC_Copy_SDRAM_Async(): dst_addr is illegal. ret=0x%x\n", ret));
			break;
		case 34:
			ret = Dd_PMC_HDMAC_Copy_SDRAM_Async(0, 1, 2, 0, (VP_CALLBACK)ct_pmc_hdmac_callback);
			Ddim_Print(("Dd_PMC_HDMAC_Copy_SDRAM_Async(): size is illegal. ret=0x%x\n", ret));
			break;
		default:
			Ddim_Print(("please check 2nd parameter!!\n"));
			break;
		}
	}
	else {
		Ddim_Print(("please check 1st parameter!!\n"));
	}
	return;
}
